#include "curveoptimization.h"
#include "ui_curveoptimization.h"

curveoptimization::curveoptimization(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::curveoptimization)
{
    ui->setupUi(this);

    this->setWindowFlags(this->windowFlags() | Qt::WindowStaysOnTopHint);
    this->setWindowModality(Qt::ApplicationModal);
    this->setWindowTitle("曲线优化");

    start();
}

curveoptimization::~curveoptimization()
{
    delete ui;
}

void curveoptimization::start() {
    renderTable("管式");
}

void curveoptimization::renderTable(QString type) {
    int row, column;
    if (type == "管式") {
        row = 8;
        column = 4;
    } else if (type == "芯片-16") {
        row = 8;
        column = 2;
    }

    ui->sampleTable->blockSignals(true);

    ui->sampleTable->setVerticalHeaderLabels(QStringList() << "A" << "B" << "C" << "D" << "E" << "F" << "G" << "H");
    for (int m = 0; m < row; m++) {
        for (int n = column; n < 12; n++) {
            QTableWidgetItem *newItem = new QTableWidgetItem();
            ui->sampleTable->setItem(m, n, newItem);
            ui->sampleTable->setColumnHidden(n, true);
        }
    }
    for (int m = 0; m < row; m++) {
        for (int n = 0; n < column; n++) {
            ui->sampleTable->setColumnHidden(n, false);
        }
    }

    ui->sampleTable->setFixedWidth(600);
    ui->sampleTable->setFixedHeight(400);
    ui->sampleTable->horizontalHeader()->setFixedHeight(20);
    ui->sampleTable->verticalHeader()->setFixedWidth(20);

    int cellHeight = (ui->sampleTable->height() - ui->sampleTable->horizontalHeader()->height()) / row - 1;
    int cellWidth = (ui->sampleTable->width() - ui->sampleTable->verticalHeader()->width()) / column - 1;
    LOG << ui->sampleTable->height()<<ui->sampleTable->horizontalHeader()->height() << ui->sampleTable->width() << ui->sampleTable->verticalHeader()->width() ;
    for (int m = 0; m < row; ++m) {
        ui->sampleTable->setRowHeight(m, cellHeight);
    }
    for (int n = 0; n < column; ++n) {
        ui->sampleTable->setColumnWidth(n, cellWidth);
    }

    ui->sampleTable->blockSignals(false);

}
